﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Collections;
using System.Windows.Forms;

namespace LibExtend
{
    public class Table
    {
        public enum State
        {
            Empty, Busy, None
        }

        public enum MouseState
        {
            Hover, Leave, Down, Up, None
        }

        Rectangle v_bound = Rectangle.Empty;
        public Rectangle Bound
        {
            get { return v_bound; }
            set { v_bound = value; }
        }

        private int v_IdBanHang = 0;
        public int IdBanHang
        {
            get { return v_IdBanHang; }
            set { v_IdBanHang = value; }
        }

        private State v_state = State.None;
        public State iState
        {
            get { return v_state; }
            set { v_state = value; }
        }

        private int v_IdBan = 0;
        public int IdBan
        {
            get { return v_IdBan; }
            set { v_IdBan = value; }
        }

        private string v_TenBan = "";
        public string TenBan
        {
            get { return v_TenBan; }
            set { v_TenBan = value; }
        }

        public DateTime Ngay { get; set; }
        public decimal ThanhTien { get; set; }
        public decimal PT_CK { get; set; }
        public decimal Tien_CK { get; set; }
        public decimal TongTien { get; set; }
        public decimal KhachTra { get; set; }
        public System.Data.DataTable DataSource { get; set; }
        public string GhiChu { get; set; }
        public System.Data.DataTable DataMerge { get; set; } 

        public Image GetImage()
        {
            if (this.iState == State.Busy || (this.TongTien > 0 && KhachTra <= 0))
                return LibExtend.Properties.Resources.tbl22;
            else
                return LibExtend.Properties.Resources.tbl2;
        }

        public Image GetSmallImage()
        {
            if (this.iState == State.Busy || (this.TongTien > 0 && KhachTra <= 0))
                return LibExtend.Properties.Resources.Busy;
            else
                return LibExtend.Properties.Resources.Table2;
        }

        public Color GetTextColor()
        {
            //if ((this.DataSource != null && this.DataSource.Rows.Count > 0 && !this.IsPayment) || this.iState == State.Booked)
            //    return Color.White;
            //else
                return Color.FromArgb(150, Color.WhiteSmoke);
        }

        public void OnPaint(PaintEventArgs pevent, MouseState mState)
        {
            if (mState == MouseState.Hover)
            {
                using (Draw dr = new Draw())
                {
                    dr.OnPaint(pevent, v_bound, (mState == MouseState.Down) ? ButtonState.Pressed : (mState == MouseState.Hover) ? ButtonState.Selected : ButtonState.None);
                }
            }

            pevent.Graphics.DrawImage(GetImage(), v_bound);

            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            Font f = new System.Drawing.Font("Arial", 12F, FontStyle.Bold);

            Rectangle rcT = v_bound;
            rcT.Height = 40;

            //SolidBrush br = new SolidBrush(GetTextColor());//((mState == MouseState.Hover) ? Color.Blue: Color.Red);
            pevent.Graphics.DrawString(TenBan, f, Brushes.White, rcT, sf);
            //br.Dispose();
        }
    }
}
